package A1;

import java.awt.*;
import javax.swing.*;

/**
 * Created by IntelliJ IDEA.
 * User: Sarah
 * Date: 17/08/2011
 * Time: 2:41:22 PM
 * To change this template use File | Settings | File Templates.
 */

public class floorUI extends JPanel {

    int numOfFloor;
    JButton[] UP, DOWN;

    /**
     * Adds the up and down buttons to each floor according to the user's input
     */
    public floorUI(int numOfFloor) {
        this.numOfFloor = numOfFloor;
        init();
        setLayout(new GridLayout(numOfFloor, 2, 20, 40));
        for (int i = numOfFloor; i >= 1; i--) {
            add(UP[i]);
            add(DOWN[i]);
        }
    }

    /**
     * Calls the elevator to the floor that the up or down button has been pressed on
     */
    protected void init() {
        UP = new JButton[numOfFloor + 1];
        DOWN = new JButton[numOfFloor + 1];
        for (int i = 1; i <= numOfFloor; i++) {
            UP[i] = new JButton(i + " Up");
            DOWN[i] = new JButton(i + " Down");
        }
        UP[numOfFloor] = new JButton();
        DOWN[1] = new JButton();
	}
}